module QuestionsHelper
  def pourcentage_oui(question)
    if question.oui != 0 || question.non != 0
      question.oui.fdiv(question.oui + question.non) * 100
    else
      0
    end
  end

  def taille_barre_oui(question)
    pourcentage = pourcentage_oui(question)
    number_with_precision(-(100-pourcentage)*2 , :precision => 1, :separator => ".", :delimiter => "")
  end

  def taille_barre_non(question)
    pourcentage = pourcentage_non(question)
    number_with_precision(-(100-pourcentage)*2, :precision => 1, :separator => ".", :delimiter => "")
  end

  def pourcentage_non(question)
    if question.oui != 0 || question.non != 0
      question.non.fdiv(question.oui + question.non) * 100
    else
      0
    end
  end

  def nombre_votes(question)
    question.oui + question.non
  end
end
